' 
' Copyright (C) 2014 Infinity CCS Ltd (http://www.infinityccs.com/)
' Copyright (C) 2008 Sasa Coh <sasacoh@gmail.com>
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program.  If not, see <http://www.gnu.org/licenses/>. 
'/


Imports System
Imports System.Collections.Generic
Imports System.Text

Namespace Common

  ''' <summary>
  ''' Call oriented interface. Offers basic session control API and events called from VoIP stack
  ''' </summary>
  ''' 
  Public MustInherit Class ICallProxy
#Region "Properties"
    ''' <summary>
    ''' Call/Session identification. All public methods refers to this identification
    ''' </summary>
    Public MustOverride Property SessionId As Integer
    Public MustOverride Property AccountId As Integer
#End Region

#Region "Events"
    ''' <summary>
    ''' CallStateChanged event trigger by VoIP stack when call state changed
    ''' </summary>
    Public Shared Event CallStateChanged(callId As Integer, callState As CallState.ESessionState, info As String, lastStatus As Integer, lastStatusText As String)
    Protected Shared Sub BaseCallStateChanged(callId As Integer, callState As CallState.ESessionState, info As String, lastStatus As Integer, lastStatusText As String)
      RaiseEvent CallStateChanged(callId, callState, info, lastStatus, lastStatusText)
    End Sub

    ''' <summary>
    ''' CallIncoming event triggered by VoIP stack when new incoming call arrived
    ''' </summary>
    Public Shared Event CallIncoming(accountId As Integer, callId As Integer, cli As String, ddi As String, clidisplay As String)
    Protected Shared Sub BaseIncomingCall(accountId As Integer, callId As Integer, cli As String, ddi As String, clidisplay As String)
      RaiseEvent CallIncoming(accountId, callId, cli, ddi, clidisplay)
    End Sub

    ''' <summary>
    ''' CallNotification event trigger by VoIP stack when call notification arrived
    ''' </summary>
    Public Shared Event CallNotification(callId As Integer, notFlag As ECallNotification, text As String)
    Protected Shared Sub BaseCallNotification(callId As Integer, notifFlag As ECallNotification, text As String)
      RaiseEvent CallNotification(callId, notifFlag, text)
    End Sub

#End Region

#Region "Public Methods"
    ''' <summary>
    ''' Make call request
    ''' </summary>
    ''' <param name="dialedNo">Calling Number</param>
    ''' <returns>Session Identification</returns>
    Public MustOverride Function makeCall(dialedNo As String, accountKey As String) As Integer

    ''' <summary>
    ''' End call
    ''' </summary>
    ''' <returns></returns>
    Public MustOverride Function endCall() As Boolean

    ''' <summary>
    ''' Report that device is alerted
    ''' </summary>
    ''' <returns></returns>
    Public MustOverride Function alerted() As Boolean

    ''' <summary>
    ''' Report that call is accepted/answered
    ''' </summary>
    ''' <returns></returns>
    Public MustOverride Function acceptCall() As Boolean

    ''' <summary>
    ''' Request call hold
    ''' </summary>
    ''' <returns></returns>
    Public MustOverride Function holdCall() As Boolean

    ''' <summary>
    ''' Request retrieve call
    ''' </summary>
    ''' <returns></returns>
    Public MustOverride Function retrieveCall() As Boolean

    ''' <summary>
    ''' Tranfer call to a given number
    ''' </summary>
    ''' <param name="number">Number to transfer call to</param>
    ''' <returns></returns>
    Public MustOverride Function xferCall(number As String) As Boolean

    ''' <summary>
    ''' Transfer call to partner session
    ''' </summary>
    ''' <param name="partnersession">Session to transfer call to</param>
    ''' <returns></returns>
    Public MustOverride Function xferCallSession(partnersession As Integer) As Boolean

    ''' <summary>
    ''' Request three party conference
    ''' </summary>
    ''' <param name="partnersession">Partner session for conference with</param>
    ''' <returns></returns>
    Public MustOverride Function threePtyCall(partnersession As Integer) As Boolean

    ''' <summary>
    ''' Request service (TODO)
    ''' </summary>
    ''' <param name="code"></param>
    ''' <param name="dest"></param>
    ''' <returns></returns>
    Public MustOverride Function serviceRequest(code As Integer, dest As String) As Boolean

    ''' <summary>
    ''' Dial digit by DTMF
    ''' </summary>
    ''' <param name="digits">digit string</param>
    ''' <param name="mode">digit mode (TODO)</param>
    ''' <returns></returns>
    Public MustOverride Function dialDtmf(digits As String, mode As EDtmfMode) As Boolean

    ''' <summary>
    ''' Retrieve codec information for this call
    ''' </summary>
    ''' <returns>codec name</returns>
    Public MustOverride Function getCurrentCodec() As String

    ''' <summary>
    ''' Make a conference 
    ''' </summary>
    ''' <returns></returns>
    Public MustOverride Function conferenceCall() As Boolean

    '''' <summary>
    '''' Send a message inside a call
    '''' </summary>
    '''' <returns></returns>
    'Public MustOverride Function sendCallMessage(message As String) As Boolean

#End Region

#Region "Null Pattern"

    ''' <summary>
    ''' 
    ''' </summary>
    Friend Class NullCallProxy
      Inherits ICallProxy
#Region "ICallProxyInterface Members"

      Public Overrides Function makeCall(dialedNo As String, accountKey As String) As Integer
        Return 1
      End Function

      Public Function makeCallByUri(uri As String) As Integer
        Return 1
      End Function

      Public Overrides Function endCall() As Boolean
        Return False
      End Function

      Public Overrides Function alerted() As Boolean
        Return False
      End Function

      Public Overrides Function acceptCall() As Boolean
        Return False
      End Function

      Public Overrides Function holdCall() As Boolean
        Return False
      End Function

      Public Overrides Function retrieveCall() As Boolean
        Return False
      End Function

      Public Overrides Function xferCall(number As String) As Boolean
        Return False
      End Function

      Public Overrides Function xferCallSession(session As Integer) As Boolean
        Return False
      End Function

      Public Overrides Function threePtyCall(session As Integer) As Boolean
        Return False
      End Function

      Public Overrides Function serviceRequest(code As Integer, dest As String) As Boolean
        Return False
      End Function

      Public Overrides Function dialDtmf(digits As String, mode As EDtmfMode) As Boolean
        Return False
      End Function

      Public Overrides Function getCurrentCodec() As String
        Return "PCMA"
      End Function

      Public Overrides Property SessionId As Integer
        Get
          Return 0
        End Get
        Set(value As Integer)

        End Set
      End Property

      Public Overrides Property AccountId As Integer
        Get
          Return 0
        End Get
        Set(value As Integer)

        End Set
      End Property

      Public Overrides Function conferenceCall() As Boolean
        Return False
      End Function

      'Public Overrides Function sendCallMessage(message As String) As Boolean
      '  Return False
      'End Function
#End Region
    End Class

#End Region

  End Class
End Namespace